<#import "/macro.ftl" as m>
<@m.page_header title='金融资产出入库明细' />
<div id="page-content-wrapper">
    <div id="page-title">
        <h3><a class="font-blue" href="/financialassets">金融资产</a> > 出入库明细</h3>
        <div id="breadcrumb-right">
            <div class="float-right">
                <a href="javascript:;" class="btn medium primary-bg" onclick="showRecreateFinancialAssetStockEntry(${financialAsset.id})">
                    <span class="button-content">重建出入库明细</span>
                </a>
            </div>
        </div>
    </div>
    <div id="page-content">
		<div class="form-row">
			<div class="form-label col-md-4">
				<label>${financialAsset.name}</label>
			</div>
			<div class="form-label col-md-2">
				<label>金额：${financialAsset.amount?string(',##0.00')}元</label>
			</div>
			<div class="form-label col-md-2">
				<label>库存：${financialAsset.inventory?string(',##0.00')}元</label>
			</div>
			<div class="form-label col-md-4">
				<label>实时库存：${calculateInventory?string(',##0.00')}元</label>
			</div>
		</div>
		<div class="form-row">
			<div class="form-label col-md-4"></div>
			<div class="form-label col-md-2">
				<label>起息日：${financialAsset.valueDate?string('yyyy-MM-dd')}</label>
			</div>
			<div class="form-label col-md-2">
				<label>到日期：${financialAsset.dueDate?string('yyyy-MM-dd')}</label>
			</div>
			<div class="form-label col-md-4">
				<label>明细累计库存：${entryCalculateInventory?string(',##0.00')}元</label>
			</div>
		</div>
    	<table class="table">
	        <thead>
	            <tr>
	            	<th>出入库日期</th>
	                <th>用途</th>
	                <th class="text-right">入库(${inStockAmount?string(',##0.00')}元)</th>
	                <th class="text-right">出库(${outStockAmount?string(',##0.00')}元)</th>
	                <th>产品</th>
	                <th>操作</th>
	            </tr>
	        </thead>
	        <tbody>
	        	<#list financialAssetStockEntries as financialAssetStockEntry>
					<tr id="${financialAssetStockEntry.id}">
						<td>${financialAssetStockEntry.postingDate?string('yyyy-MM-dd HH:mm:ss')}</td>
		                <td>${financialAssetStockEntry.purposeDescription}</td>
		                <td class="text-right"><#if financialAssetStockEntry.type=="In">${financialAssetStockEntry.amount?string(',##0.00')}</#if></td>
		                <td class="text-right"><#if financialAssetStockEntry.type=="Out">${financialAssetStockEntry.amount?string(',##0.00')}</#if></td>
		                <td><#if financialAssetStockEntry.product??>${financialAssetStockEntry.product.name}</#if></td>
		            	<td>
		                	<a href="javascript:;" class="btn medium primary-bg" onclick="showDeleteFinancialAssetStockEntry(${financialAssetStockEntry.id});">
			                    <span class="button-content">删除</span>
			                </a>
		             	</td>
		            </tr>
				</#list>    
	    	</tbody>
	    </table>
    </div>
</div>
<script>

function showDeleteFinancialAssetStockEntry( id ){
	$.messager.confirm( "提示", "确定删除出入库记录吗？", function(){
		$.ajax({
		    url: '/financialassetstockentries/' + id,
		    type: 'POST',
		    data: { _method: 'DELETE' }
		})
	    .done(function(data){
	     	if(data["status"] == "success"){
	     		$.jGrowl("删除出入库记录成功", {sticky:!1,position:"top-right",theme:"bg-green"});
	     		$('.table').find('tr[id=' + id + ']').remove();
	     	}else{
	     		$.jGrowl(data["message"], {sticky:!1,position:"top-right",theme:"bg-red"});
	     	}
	     })
	     .fail(function(){
	     	$.jGrowl("删除出入库记录失败", {sticky:!1,position:"top-right",theme:"bg-red"});
	     });
	});
};

function showRecreateFinancialAssetStockEntry( id ){
	$.messager.confirm( "提示", "重建出入库记录吗？", function(){
		$.ajax({
		    url: '/financialassetstockentries/' + id + '/recreate',
		    type: 'POST'
		})
	    .done(function(data){
	     	if(data["status"] == "success"){
	     		$.jGrowl("重建出入库记录成功", {sticky:!1,position:"top-right",theme:"bg-green"});
	     		window.location.reload();
	     	}else{
	     		$.jGrowl(data["message"], {sticky:!1,position:"top-right",theme:"bg-red"});
	     	}
	     })
	     .fail(function(){
	     	$.jGrowl("重建出入库记录失败", {sticky:!1,position:"top-right",theme:"bg-red"});
	     });
	});
};

</script>